package genome;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import tool.Utility;

public class IGTest {

	private IG g1; private IG g2;
	private int[] def_genome1 = {0,0,0};
	private int[] def_genome2 = {3,4,5};
	
	private int size = 3;
	
	@Before
	public void setUp() throws Exception {
		g1 = new IG(size);
		g1.genome=def_genome1;
		g2 = new IG(size);
		g2.genome=def_genome2;
	}

	@Test
	public void testIncrement() {
		for(int i=0;i<5;i++){
			g1 = (IG)g1.increment();
		}
		assertTrue(g1.genome[0]==1 && g1.genome[1]==1);
	}

	@Test
	public void testGenerateSpace() {
		ArrayList<Genotype> space = g1.generateSpace();
		assertTrue(space.size()==Math.pow(IG.MX_VAL+1,size));
		System.out.println(space);
	}
	
	@Test
	public void testDistanceTo(){
		double dist = g1.distanceTo(g2);
		System.out.println(dist);
		assertTrue(dist==Utility.roundToSignificantFigures(Math.sqrt(50), 5));
	}
	
	@Test
	public void testtoVector(){
		double[] v = g2.toVector();
		System.out.println(g2+" is "+v[0]);
		assertTrue(Utility.roundToSignificantFigures(v[0], 5)==Utility.roundToSignificantFigures(Math.sin(3)+Math.sin(4)+Math.sin(5), 5));
	}

}
